package com.vip.jwt.common.utils;

import cn.hutool.core.util.StrUtil;
import com.vip.jwt.common.exception.MyException;

import java.lang.reflect.Field;

public class ObjectUtil {

    /**
     * 检查对象中是否有空字段
     * @param obj
     * @return
     * @throws IllegalAccessException
     */
    public static boolean checkObjectFieldIsNull(Object obj){
        for(Field f : obj.getClass().getDeclaredFields()){
            f.setAccessible(true);
            try {
                if(null==f.get(obj) || StrUtil.isEmpty(f.get(obj)+"")){
                    return true;
                }
            } catch (IllegalAccessException e) {
                throw new MyException("检查对象中是否有空字段时出现错误");
            }
        }
        return false;
    }

}
